/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package argentracker.activeentity.property;

import argentracker.activeentity.ActiveEntity;
import argentracker.activeentity.P;

/**
 * briefly description.
 * 
 * extense description.
 * 
 * @author matero (matero _at_ gmail _dot_ com)
 */
public class ByteProperty<AE extends ActiveEntity<AE>> extends P<Byte, AE> {

    public static Byte DEFAULT_VALUE = null;

    /**
     * Constructs an Byte property with no name and {@link #DEFAULT_VALUE} as default value.
     */
    public ByteProperty() {
        this(NO_NAME, DEFAULT_VALUE);
    }

    /**
     * Construts an Byte property defining its name, and setting {@link #DEFAULT_VALUE} as default value.
     * 
     * @param propertyName
     */
    public ByteProperty(String propertyName) {
        this(propertyName, DEFAULT_VALUE);
    }

    /**
     * Constructs an Byte property defining its name and default value.
     * 
     * @param propertyName
     */
    public ByteProperty(String propertyName, Byte propertyDefaultValue) {
        super(Byte.class, propertyName, propertyDefaultValue);
    }

    @Override
    public Byte interpret(Object value) {
        Long number = (Long) value;
        return Byte.valueOf(number.byteValue());
    }

    @Override
    public Object traduct(Byte value) {
        return value == null ? getDefaultValue() : value;
    }
}
